package com.mcptt.config.body.info.mcvideo;

import android.util.Xml;

import com.cloudptt.api.product.log.Log;
import com.mcptt.config.body.info.mcptt.McpttInfoBody_NewCall;

import org.xmlpull.v1.XmlPullParser;

import java.io.ByteArrayInputStream;
import java.io.UnsupportedEncodingException;

public class McvideoInfoBody_Conference {

	private static final String THIS_FILE = "McvideoInfoBody_Conference";
	private static final String End_Mcvideo_Tag = "</mcvideoinfo>";
	private static final String Name_RequestUri = "mcvideo-request-uri";
	private static final String Name_Url = "mcvideoURI";
	private String groupId = "";

	public McvideoInfoBody_Conference(String groupId)
	{
		this.groupId = groupId;
	}
	private McvideoInfoBody_Conference()
	{
		this.groupId = "";
	}

	public static McvideoInfoBody_Conference parseXmlStr(String xmlStr) throws Exception
	{
		McvideoInfoBody_Conference body = new McvideoInfoBody_Conference();
		int valType = 0;
//		String key = End_Mcvideo_Tag;

		int index = xmlStr.indexOf(End_Mcvideo_Tag);
		Log.d(THIS_FILE, "McvideoInfoBody_Conference parseXmlStr index = " + index);

//	    if(index <= 0)
//	    {
//	    	key = End_Mcvideo_Tag;
//	    	index = xmlStr.indexOf(key);
//	    }
		xmlStr= xmlStr.substring(0, index + End_Mcvideo_Tag.length());
		xmlStr = xmlStr.trim();

		ByteArrayInputStream strIs = new  ByteArrayInputStream(xmlStr.getBytes());
		XmlPullParser pullParser = Xml.newPullParser();
		pullParser.setInput(strIs, "UTF-8"); //为Pull解释器设置要解析的XML数据
		int event = pullParser.getEventType();

		while (event != XmlPullParser.END_DOCUMENT){

			switch (event) {

				case XmlPullParser.START_DOCUMENT:
					break;
				case XmlPullParser.START_TAG:
					if (Name_RequestUri.equals(pullParser.getName()))
					{
						valType = 1;
					}
					else if (Name_Url.equals(pullParser.getName()))
					{
						String value = pullParser.nextText();
						Log.debug(McvideoInfoBody_NewCall.class, "McvideoInfoBody_Conference valType = " + valType + " value = " + value);
						if(valType == 1)
						{
							body.groupId = value;
						}

					}
					break;

				case XmlPullParser.END_TAG:
					break;

			}

			event = pullParser.next();
		}

		return body;
	}
	
	public String toString()
	{
		StringBuffer strBuff = new StringBuffer();
		strBuff.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>").append("\r\n");
		strBuff.append("<mcvideoinfo>").append("\r\n");
		strBuff.append("<mcvideo-Params>").append("\r\n");
		strBuff.append("<mcvideo-request-uri>").append("\r\n");
		strBuff.append("<mcvideoURI>").append(groupId).append("</mcvideoURI>").append("\r\n");
		strBuff.append("</mcvideo-request-uri>").append("\r\n");
		strBuff.append("</mcvideo-Params>").append("\r\n");
		strBuff.append("</mcvideoinfo>");
		
		try {
			return new String(strBuff.toString().getBytes(),"UTF-8");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return strBuff.toString();
	}

	public String toValueString()
	{
		StringBuffer strBuff = new StringBuffer("McvideoInfoBody_Conference:");
		strBuff.append("groupId = ").append(groupId).append("\r\n");

		return strBuff.toString();
	}

	public String getGroupId() {
		return groupId;
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
